package tree.tree2.symmetry.ModifyAndConstruct;

import tree.TreeNode;

/**
 * @ClassName InvertTree
 * @Description TODO
 * @Author lenovo
 * @Date 2023-05-09 9:58
 * @Version 1.0
 * @Comment Magic. Do not touch.
 * If this comment is removed. the program will blow up
 */
public class InvertTree {

    /**
     * 反转树
     * @param root
     * @return
     */
    public TreeNode invertTree(TreeNode root) {
        if(root == null) return root;
        invertTree(root.left);
        invertTree(root.right);
        TreeNode tempNode = root.left;
        root.left = root.right;
        root.right = tempNode;
        return root;
    }


    public static void main(String[] args) {
        InvertTree invertTree = new InvertTree();
        TreeNode root = new TreeNode(1);
        root.left = new TreeNode(2);
        root.right = new TreeNode(3);
        System.out.println(invertTree.invertTree(root));
    }
}